import {defineStore} from 'pinia' //引入pinia

export const useMusicStore = defineStore('musicStore', {
    state: () => {
        return {
            MusicPlayList: JSON.parse(window.localStorage.getItem("MusicPlayList")),
            CurrentPlayMusic: JSON.parse(window.localStorage.getItem("CurrentPlayMusic")) ? JSON.parse(window.localStorage.getItem("CurrentPlayMusic")) : {},
            Lyric: JSON.parse(window.localStorage.getItem("Lyric")),
            UserInfo: JSON.parse(window.localStorage.getItem("UserInfo")),
        }
    },
    actions: {
        changeMusicPlayList(list) {
            this.MusicPlayList = list
            window.localStorage.setItem("MusicPlayList", JSON.stringify(list))
        },
        changeLyric(Lyric) {
            this.Lyric = Lyric
            window.localStorage.setItem("Lyric", JSON.stringify(Lyric))
        },
        changeCurrentPlayMusic(curr) {
            this.CurrentPlayMusic = curr
            window.localStorage.setItem("CurrentPlayMusic", JSON.stringify(curr))
        },
        getUserInfo(UserInfo) {
            this.UserInfo = UserInfo
            window.localStorage.setItem("UserInfo", JSON.stringify(UserInfo))
        }
    },
    getters: {
        url(state) {
            return state.CurrentPlayMusic.url
        },
        id(state) {
            return state.CurrentPlayMusic.id
        },
        img(state) {
            return state.CurrentPlayMusic.img
        },
        singer(state) {
            return state.CurrentPlayMusic.singer
        },
        song(state) {
            return state.CurrentPlayMusic.song
        },
        dt(state) {
            return state.CurrentPlayMusic.dt
        },
        al(state) {
            return state.CurrentPlayMusic.al
        },
        songListName(state) {
            return state.CurrentPlayMusic.songListName
        },
        musicList(state) {
            return state.MusicPlayList
        },
    }
})
